//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<signal.h>
///	@path	~/src/lib/system/
///	@date	2007/10/17
///	@desc	Encapsulate signal(event) IPC.

#pragma once

#include "xeres.h"

#include "lib/utilities/string.h"
#include "lib/utilities/time.h"

namespace xeres {

	/*!
		\class	Signal
		\brief	Setup synchronization signal across threads or processes.
	*/
	class Signal
	{
	public:

		/// \name Constructor & Destructor
		//@{

		/// \ctor_set
		Signal( bool manualReset = false , bool initSignaled = false , const WString& name = _S("") );

		/// \ctor_set
		Signal( const WString& name );

		/// \ctor_copy
		Signal( const Signal& rhs );

		/// \dtor
		~Signal( void );
		//@}

		/// \name Signal Manipulation
		//@{

		/*!
			\brief		Wait for signal comes in.
		*/
		void Wait( void );

		/*!
			\brief		Wait for signal comes in, in specific time.
			\return		True if signal comes in in time.
			\param[in]	time	Wait time.
			
		*/
		bool Wait( const Time& time );

		/*!
			\brief		Set signaled states.
		*/
		void SetSignal( void );

		/*!
			\brief		Set non-signaled state.
		*/
		void Reset( void );

	protected:

		/*!
			\brief		Get handle of Signal. For internal use.
		*/
		void * handle( void ) const { return m_handle; }

		//@}

	private:

		// handle
		void *		m_handle;
	};

} // namespace xeres
